# Maintainer: Joel Holdsworth <jholdsworth@nvidia.com>

_realname=conan
pkgbase=mingw-w64-python-conan
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.57.0
pkgrel=1
pkgdesc="A distributed, open source, C/C++ package manager (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('spdx:MIT')
url="https://conan.io"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-pyjwt>=1.4.0"
         "${MINGW_PACKAGE_PREFIX}-python-requests>=2.25"
         "${MINGW_PACKAGE_PREFIX}-python-urllib3>=1.26.6"
         "${MINGW_PACKAGE_PREFIX}-python-colorama>=0.3.3"
         "${MINGW_PACKAGE_PREFIX}-python-yaml>=3.11"
         "${MINGW_PACKAGE_PREFIX}-python-patch-ng>=1.17.4"
         "${MINGW_PACKAGE_PREFIX}-python-fasteners>=0.14.1"
         "${MINGW_PACKAGE_PREFIX}-python-six>=1.10.0"
         "${MINGW_PACKAGE_PREFIX}-python-node-semver>=0.6.1"
         "${MINGW_PACKAGE_PREFIX}-python-distro>=1.0.2"
         "${MINGW_PACKAGE_PREFIX}-python-pygments>=2.0"
         "${MINGW_PACKAGE_PREFIX}-python-tqdm>=4.28.1"
         "${MINGW_PACKAGE_PREFIX}-python-jinja>=3.0"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil>=2.7.0"
         "${MINGW_PACKAGE_PREFIX}-python-bottle>=0.12.8"
         "${MINGW_PACKAGE_PREFIX}-python-pluginbase>=0.5")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/conan-io/conan/archive/${pkgver}.tar.gz"
        "0001-Loosened-node-semver-version-requirement.patch")
sha256sums=('bf0b5c1a63d9935fe0c83d94eae28a008e1bbe078c0bc7cb9fb53afb86d635d7'
            'e45a784ccc7ed9fbc1f203b0cba1f3580e06120b2a2b6c45b9ad17dedb297a8c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Apply patches
  patch -Nbp1 -i "${srcdir}/0001-Loosened-node-semver-version-requirement.patch"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
   ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  # Remove build machine shebangs
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -i 's/\#\!.*//' $_f
  done

  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
  install -Dm644 contributors.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/contributors.txt"
}
